package b.utils.impl

import akka.NotUsed
import b.utils.api.T底层Service
import b.utils.entity.{CC多个序号申请Command, CC序号申请Command, C流水号PersistentEntity}
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry

import scala.concurrent.ExecutionContext

/**
  * 贲国称 于 2016/12/20 创建。
  */
class C底层ServiceImpl(registry: PersistentEntityRegistry)(implicit ex: ExecutionContext) extends T底层Service {

  override def f申请流水号(id: String): ServiceCall[NotUsed, Long] = ServiceCall { _ =>
    val ref = registry.refFor[C流水号PersistentEntity](s"/sequences/$id")
    ref.ask[CC序号申请Command](CC序号申请Command(id)).map(_.v序号)
  }

  override def f申请多个流水号(id: String, several: Int): ServiceCall[NotUsed, Array[Long]] = ServiceCall { _ =>
    val ref = registry.refFor[C流水号PersistentEntity](s"/sequences/$id")
    ref.ask[CC多个序号申请Command](CC多个序号申请Command(id, several))
  }

}
